﻿@using System.Data
@{
    ViewBag.Title = "Window";
    Layout = "~/Areas/Admin/Views/Shared/AdminLayout.cshtml";
}
<script src="/Scripts/jquery-1.8.2.min.js"></script>
<script src="/Scripts/kindeditor/kindeditor-all-min.js"></script>
<link href="/Scripts/kindeditor/themes/default/default.css" rel="stylesheet" />
<link rel="stylesheet" href="/Scripts/kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="/Scripts/kindeditor/lang/zh-CN.js"></script>
<script charset="utf-8" src="/Scripts/kindeditor/plugins/code/prettify.js"></script>
<script src="~/Scripts/kindeditor/plugins/insertfile/insertfile.js"></script>

<table class="edit_table">


    <tr>
        <td colspan="2"><label>联系方式</label></td>
    </tr>
    <tr>
        <td colspan="2">
            <textarea id="content1" style="width:600px;height:400px;visibility:hidden;"></textarea>
        </td>

    </tr>


    <tr>
        <td colspan="2">
            <div class="botton" style="margin-left: 50px;" onclick="edit()">保存</div>
            <div class="botton" style="margin-left: 50px;" onclick="javascript: history.go(-1);">取消</div>
        </td>
    </tr>
</table>

<script>


    var editor;
    KindEditor.ready(function (K) {

        editor = K.create('#content1', {
            cssPath: '/Scripts/kindeditor/plugins/code/prettify.css',
            uploadJson: '/Scripts/kindeditor/aspnet/upload_json.ashx',
            fileManagerJson: '/Scripts/kindeditor/aspnet/file_manager_json.ashx',
            allowFileManager: true,
            afterCreate: function () {
                var self = this;
                K.ctrl(document, 13, function () {
                    self.sync();
                    K('form[name=example]')[0].submit();
                });
                K.ctrl(self.edit.doc, 13, function () {
                    self.sync();
                    K('form[name=example]')[0].submit();
                });
            }, afterUpload: function (url) {
                var arr = url.split('<');
                if (arr.length == 2) {
                    $("#keUrl").val(arr[0]);
                    $("#keTitle").val(arr[1]);
                }
            }
        });
        prettyPrint();
    });
    var id = "3";
    $(function() {
        $.post("@Url.Action("GetData")", { id: id }, function (data) {

            var item = JSON.parse(data)[0];
            editor.html(item.Content);
        });
    });

    function edit() {
        var text = editor.html(); //描述
        if (text.replace(/\s/g, "").length == 0) {
            alert("请输入联系方式！");
            return false;
        }

        $.post("@Url.Action("Edit")", { id: id, content: encodeURIComponent(text) }, function (row) {
            if (row > 0) {
                alert("操作成功！");
            } else {

                alert("操作失败！");
            }
        });
    }
</script>

